package dao;

import pojo.User;
import utils.JDBCUtils;

import java.sql.ResultSet;
import java.sql.SQLException;

public class UserDAO {

    private static final String TABLE_NAME = "tb_users";

    // 用户登录验证
    public static User login(String username, String password) throws SQLException {
        String sql = "SELECT * FROM " + TABLE_NAME + " WHERE username = ? AND password = ?";
        ResultSet resultSet = (ResultSet) JDBCUtils.execute(sql, username, password);
        if (resultSet.next()) {
            User user = new User();
            user.setUserId(resultSet.getInt("user_id"));
            user.setUsername(resultSet.getString("username"));
            user.setPassword(resultSet.getString("password"));
            return user;
        }
        return null;
    }
}
